<?php

namespace app\service;

class Log
{
    /**
     * log
     * @param        $level
     * @param string $message
     * @param null   $data
     */
    protected static function log($level, string $message = '', $data = null)
    {
        $logFile = LOG_PATH . DIRECTORY_SEPARATOR . date('Ymd') . '.log';
        if ($data) {
            $message .= PHP_EOL . print_r($data, 1);
        }

        $content = date('Y-m-d H:i:s').' ['. $level.'] '.$message;

        file_put_contents($logFile, $content, FILE_APPEND);
    }

    /**
     * error
     * @param string $message
     * @param null   $data
     */
    public static function error(string $message = '', $data = null)
    {
        self::log('error', $message, $data);
    }

    /**
     * info
     * @param string $message
     * @param null   $data
     */
    public static function info(string $message = '', $data = null)
    {
        self::log('info', $message, $data);
    }

    /**
     * warning
     * @param string $message
     * @param null   $data
     */
    public static function warning(string $message = '', $data = null)
    {
        self::log('warning', $message, $data);
    }
}